package com.zjw.dao.impl;

import com.zjw.dao.BaseDao;
import com.zjw.entity.Type;
import com.zjw.dao.TypeDao;
import com.zjw.utils.ConnectionUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 好物类别表(Type)表数据库访问层实现类
 *
 * @author 翟
 * @since 2025-04-09 09:21:58
 */
public class TypeDaoImpl extends BaseDao implements TypeDao {

    public TypeDaoImpl(Connection connection) {
        super(connection);
    }

    @Override
    public List<Type> selectAll() throws SQLException {
        String sql = "select type_id , type_name from type";
        ResultSet resultSet = null;
        List<Type> list = null;
        try {
            list = new ArrayList<>();
            resultSet = executeQuery(sql);
            while (resultSet.next()){
                Type type = new Type();
                type.setTypeId(resultSet.getInt("type_id"));
                type.setTypeName(resultSet.getString("type_name"));
                list.add(type);
            }
        } finally {
            ConnectionUtil.closeALL(resultSet , null , null);
        }
        return list;
    }
}
